

//
//  ZInternationalViewController.m
//  ZQLearn
//
//  Created by macfeel on 2019/6/12.
//  Copyright © 2019 macfeel. All rights reserved.
//

#import "ZInternationalViewController.h"
#import "PicAndTxtCollectionViewCell.h"

@interface ZInternationalViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,strong)UICollectionView *collectionView;

@property(nonatomic,strong)NSArray *imageArray;

@property(nonatomic,strong)NSMutableArray *dataArray;


@end

@implementation ZInternationalViewController

static NSString *iconCellid = @"PicAndTxt";


- (void)viewDidLoad {
    
    [super viewDidLoad];
     [self.navigationItem setItemWithTitle:@"国际新闻" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    self.dataArray = [NSMutableArray array];
    [self makeUI];
    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barTintColor = kBlackColor;
    
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.barTintColor = ThemeBlue;
}
- (void)setIconArray:(NSArray *)iconArray{
    
    _iconArray = iconArray;
    
    [self makeUI];
    
    _collectionView.delegate = self;
    
    _collectionView.dataSource = self;
    
    for (NSDictionary *dict in iconArray) {
        CommonModel *model = [CommonModel mj_objectWithKeyValues:dict];
        model.photo = [NSString stringWithFormat:@"%@%@",kPicServerUrl,model.photo];
        YYLog(@"iiii%@",model.content);
        [self.dataArray addObject:model];
    }
    
//    self.imageArray = iconArray;
    
    [self.collectionView reloadData];
}


-(void)makeUI{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //设置itemSize
    ////这个属性决定了可以急等分屏幕并决定 是否滚动
    layout.itemSize = CGSizeMake(ScreenWidth,ScreenHeight);
    
    ///横向的  ******** 这个是关键中的关键   如果要横向布局，这个是必须的
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    //这三个属性至关重要
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(8, 0, 0, 0);
    
    //2.初始化collectionView
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth,ScreenHeight) collectionViewLayout:layout];
    _collectionView.bounces = YES;
//    _collectionView.delegate = self;
    _collectionView.pagingEnabled = YES;
    _collectionView.showsHorizontalScrollIndicator = false;
    _collectionView.backgroundColor = kBlackColor;
//    [_collectionView registerClass:[PicAndTxtCollectionViewCell class] forCellWithReuseIdentifier:iconCellID];
    [_collectionView registerNib:[UINib nibWithNibName:@"PicAndTxtCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:iconCellid];
    
    [self.view addSubview:_collectionView];
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.dataArray.count;
//    return self.imageArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    CommonModel *model = self.dataArray[indexPath.row];
    
    PicAndTxtCollectionViewCell *cell = (PicAndTxtCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:iconCellid forIndexPath:indexPath];
    
//    cell.iconImg.image = WDImgName(self.imageArray[indexPath.row]);
    
    [cell.iconImg sd_setImageWithURL:[NSURL URLWithString:model.photo]];
    
    cell.txtLab.text = model.content;
    
    //    if (_iconArray.count > indexPath.row) {
    //        WDFourIconModel *model = _iconArray[indexPath.row];
    //        [cell configData:model];
    //    }
    
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    YYLog(@"当前滑动到:%ld",(long)indexPath.row);
}




@end
